|
1
|
|
|
'use strict'; |
|
2
|
|
|
const Http = require('./Http'); |
|
3
|
|
|
const CONSTANT = require('../utils/lang'); |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* @param array $body |
|
7
|
|
|
* @param string $message |
|
8
|
|
|
* @return \Http\JsonResponse |
|
9
|
|
|
*/ |
|
10
|
|
|
function success(body = [], message = CONSTANT.GENERAL.SUCCESS) { |
|
11
|
|
|
return send(Http.Codes[Http.SUCCESS], message, body, null); |
|
12
|
|
|
} |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @return \Http\JsonResponse |
|
16
|
|
|
*/ |
|
17
|
|
|
function authenticationError() { |
|
18
|
|
|
return send(Http.Codes[Http.UNAUTHORISED], CONSTANT.GENERAL.UNAUTHENTICATED, {}, null); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @param string $message |
|
23
|
|
|
* @param null $exception |
|
24
|
|
|
* @param array $body |
|
25
|
|
|
* @return \Http\JsonResponse |
|
26
|
|
|
*/ |
|
27
|
|
|
function failure(message = CONSTANT.GENERAL.FAILURE, exception = null, body = []) { |
|
28
|
|
|
return send(Http.Codes[Http.BAD_REQUEST], message, body, exception); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @param string $message |
|
33
|
|
|
* @param null $exception |
|
34
|
|
|
* @param array $body |
|
35
|
|
|
* @return \Http\JsonResponse |
|
36
|
|
|
*/ |
|
37
|
|
|
function validationError(message = CONSTANT.GENERAL.FAILURE, exception = null, body = []) { |
|
38
|
|
|
return send(Http.Codes[Http.VALIDATION_ERROR], message, body, exception); |
|
39
|
|
|
} |
|
40
|
|
|
/** |
|
41
|
|
|
* @param status |
|
42
|
|
|
* @param message |
|
43
|
|
|
* @param body |
|
44
|
|
|
* @param exception |
|
45
|
|
|
* @return \Http\JsonResponse |
|
46
|
|
|
*/ |
|
47
|
|
|
function send(status, message, body, exception) { |
|
48
|
|
|
return { |
|
49
|
|
|
status: status, |
|
50
|
|
|
message: message, |
|
51
|
|
|
body: body, |
|
52
|
|
|
exception: exception, |
|
53
|
|
|
}; |
|
54
|
|
|
// return response()->json({ |
|
55
|
|
|
// 'status' : $status, |
|
56
|
|
|
// 'message' : $message, |
|
57
|
|
|
// 'body' : $body, |
|
58
|
|
|
// 'exception' : $exception |
|
59
|
|
|
// }, $status, [], JSON_UNESCAPED_UNICODE ); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
module.exports = { |
|
63
|
|
|
success: success, |
|
64
|
|
|
authenticationError: authenticationError, |
|
65
|
|
|
failure: failure, |
|
66
|
|
|
validationError: validationError, |
|
67
|
|
|
}; |
|
68
|
|
|
|